-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Rewrite of instance.md, introducing data-methods.md #514
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
@skirtles-code thank you for bringing this! From a quick glance, it makes a lot of sense to me, will look in detail today |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
First of all, thank you for the huge effort that you put into this rewrite, @skirtles-code! It's a very thoughtful addition and I believe we should merge it.
I've added a few notes and nitpicks for your consideration, would be happy to discuss!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@NataliaTepluhina Sorry, I've made a right mess of this review process.
When I first created this PR I went through and carefully annotated my changes to explain exactly what I'd done and why. I didn't want anyone to have to try to review it without a proper explanation from me.
However, I now realise that I'm the only person who could see those comments. Oops.
I'm going to click the big green button and hopefully that'll make my original comments visible to everybody. I stress that these were all written prior to your feedback, which I will now go through and address individually.
Sorry about that.
@NataliaTepluhina As far as I'm concerned this is now good to be merged. I haven't marked the conversations as Resolved as I suspect that'll make them harder to read but I can go through and mark all mine as resolved if you want. Let me know if you'd prefer further changes. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Incredible work, thank you so much @skirtles-code for all the detailed explanations you added to your changes! I have a few additional minor tweaks but in general changes look good to me 👍🏻
src/guide/data-methods.md
Outdated
In cases where a component is only used once, the debouncing can be applied directly within `methods`: | ||
|
||
```js | ||
const app = Vue.createApp({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to show importing _
from lodash in this code snippet as it's not completely clear to people without lodash experience what is an underscore here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've updated this example to try to address this. It isn't quite as straightforward as it sounded because (I think) it needs to use a CDN version of Lodash for consistency with the other examples. That leaves the _
not explicitly defined. I've added a comment in the code to try to clarify a bit more.
src/guide/data-methods.md
Outdated
|
||
## Methods | ||
|
||
You might be tempted to put functions in your `data` so that you can use them as methods: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've never encountered anyone who does this (putting functions in data
as methods), no matter how much of a beginner they are so IMHO this might not be the best approach to introduce methods
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I made a similar observation here: https://github.com/vuejs/docs-next/pull/514/files/932839b6f612d79f299ab7e45604e0188d327e96#r491639058
I'll give it some more thought. I probably just need to delete most of that introduction and get to the point.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While this is theoretically possible, I'm think this would introduce an anti-pattern and may be more harmful than helpful. However, I do think this would make an interesting blog post!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've rewritten the Methods section. A few small pieces remain but it's mostly new.
As a result, the sections on Data Properties and Methods aren't really linked anymore. They could be split into two pages, though they would be quite short compared to the rest of the guide.
I've given up on trying to explain that the properties created by methods
aren't reactive. There are plenty of more important points to hit.
src/guide/data-methods.md
Outdated
|
||
## Data Properties | ||
|
||
The `data` function for a component is called as part of creating a new component instance. It should return an object, which Vue wraps in its reactivity system and stores on the instance as `$data`. For convenience, any top-level properties of that object are also exposed directly via the component instance: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The `data` function for a component is called as part of creating a new component instance. It should return an object, which Vue wraps in its reactivity system and stores on the instance as `$data`. For convenience, any top-level properties of that object are also exposed directly via the component instance: | |
The `data` property for a component is called as part of creating a new component instance. It is a function that should return an object, which Vue will then wrap in its reactivity system and store on the component instance as `$data`. For convenience, any top-level properties of that object are also exposed directly via the component instance: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Suggested edits are motivated by people not as familiar with JS, so calling it a property would be easier to follow initially, and then defining it technically should allow them that gradual ease into the concepts for data.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The later parts are now integrated.
I don't think we can open the paragraph with 'The data
property' because that would conflict with the more common meaning of 'data property'.
I've had a go at rewording the start of this paragraph to take things slower.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the detailed work on this @skirtles-code! Looking forward to giving this another look once the changes and discussion have been resolved!
@NataliaTepluhina @phanan @bencodezen Thanks for all the feedback. I think I've addressed all the concerns raised so far. The Methods section is almost completely rewritten since you last saw it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@skirtles-code thanks for Methods
rewrite! Looks good to me 👍🏻
@phanan @bencodezen I am going to merge this one and if you want more changes to the doc, let's make it iteratively on follow-up PRs |
* docs: experimental rewrite of instance.md, introducing data-methods.md * docs: cut material from instance.md that isn't on topic * docs: move data-methods.md to after template-syntax.md * fix: change 'application' to 'component' in template-syntax.md * fix: use bold when introducing new terms in instance.md * docs: rewrite data-methods.md
This could take a while...
Introduction
This is intended as a discussion starter, not necessarily something that should be merged. I could have just opened an issue but I don't think I could have properly conveyed what I wanted to say. Rather than just criticising the current version of
instance.md
I've tried to fix the problems myself. Opinions may vary as to whether I've succeeded.To be clear, this definitely shouldn't be merged in its present form. At the very least I'll need to go through other pages to update any links. I won't bother doing that unless there's a realistic chance of it being merged.Update: I'm now happy for it to be merged.I've gone through and added inline review comments to this PR. I think they're necessary but they do make reading the finished files a bit difficult. I suggest reading the files without my comments first to get an overall feel for the finished result.
The diff isn't necessarily super helpful. While my version does borrow some small passages from the current version it's mostly a rewrite. Some of the structure and narrative are similar to the previous version but the wording is mostly new. The exceptions are the two sections about the lifecycle, which are almost unchanged.
The relevant pages are available at:
The Problem
instance.md
has evolved over many years. But what is it actually about? What are we trying to explain and why?I feel like it's been tweaked and patched so many times that the original narrative has become somewhat blurred.
Vue 3 then introduced new problems. The concept of the 'Vue instance' doesn't really exist anymore. The closest match is a 'component instance', which behaves much the same as a
vm
in Vue 2.On its own that wouldn't be a problem but the introduction of application instances makes it much, much more difficult to explain what's going on. Trying to write an explanation that navigates through all the potential misunderstandings without getting lost in the weeds is not at all easy.
In my opinion, the current version doesn't make a clear enough distinction between application instances and component instances. The term 'component instance' isn't even used but I think it's unavoidable to qualify the word 'instance' in some way. I don't think there's any reason to avoid the word 'component', the basic concept having been introduced in the guide's Introduction.
My Attempted Solution
I've had a go at writing my own explanation of these topics. I've also moved some material out to a new page, called
data-methods.md
.Whether this is an improvement over the current documentation is subjective. I prefer it (as a totally impartial judge). Whether you agree or not, hopefully it'll help as a discussion starter to find the right balance.
Please feel free to focus any feedback on the bits you don't like. No sugar coating required.